from testprintlog import printlog
import returnJsonResult
import sys,ast
# -*- coding: utf-8 -*-
# @Time    : 2021/5/27 13:47
__author__ = 'wangd'
sys.setrecursionlimit(3000)

def get_value(new_json,key,nullList):
    if isinstance(new_json,dict):
        new_json_keys = get_dic_keys(new_json)
        for k in new_json_keys:
            if k == key:
                value = get_keys_values(key,new_json)
                nullList.append(value)
            else:
                keynew_json=get_keys_values(k,new_json)
                get_value(keynew_json,key,nullList)

    elif isinstance(new_json,list):
        for i in new_json:
            get_value(i,key,nullList)
    elif isinstance(new_json,str) and "{" in new_json:
        if is_string_dict(new_json):
            strTojson=ast.literal_eval(new_json)
            get_value(strTojson,key,nullList)
        else:
            pass
    return nullList

def get_keys_values(keys,dics):
    value=dics[keys]
    return value


def get_dic_keys(dics):
    keys=dics.keys()
    return keys


def is_string_dict(log_content):
    try:
        eval(log_content)
    except SyntaxError:
        return False
    return True

a=get_value(returnJsonResult.recommendlson,"markPics",[])
print(a)
b=get_value(returnJsonResult.recommendlson,"userName",[])
print(b)
